<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">服务人员列表</div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <form class="toolbar-form" action="" autocomplete="off">
                            <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                            <div class="am-u-sm-12 am-u-md-9 am-u-sm-push-3">
                                <div class="am fr">
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入昵称/姓名/手机号"
                                                   value="<?= $request->get('search') ?>">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search"
                                                        type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="__am-scrollable-horizontal am-u-sm-12 am-padding-bottom-lg">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th>用户ID</th>
                                <th>微信头像</th>
                                <th>微信昵称</th>
                                <th>服务等级</th>
                                <th>
                                    <p>姓名</p>
                                    <p>手机号</p>
                                </th>
                                <th>
                                    <p>累计金额</p>
                                    <p>可提现金额</p>
                                </th>
                                <th>成为时间</th>
                                <th>是否是队长</th>
                                <th>所属团队</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle"><?= $item['user_id'] ?></td>
                                    <td class="am-text-middle">
                                        <a href="<?= $item['avatarUrl'] ?>" title="点击查看大图" target="_blank">
                                            <img src="<?= $item['avatarUrl'] ?>"
                                                 width="50" height="50" alt="">
                                        </a>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['nickName'] ?></span></p>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['level_name'] ?></span></p>
                                    </td>

                                    <td class="am-text-middle">
                                        <?php if (!empty($item['real_name']) || !empty($item['mobile'])): ?>
                                            <p><?= $item['real_name'] ?: '--' ?></p>
                                            <p><?= $item['mobile'] ?: '--' ?></p>
                                        <?php else: ?>
                                            <p>--</p>
                                        <?php endif; ?>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><?= sprintf('%.2f', $item['money'] + $item['freeze_money'] + $item['total_money']) ?></p>
                                        <p><?= $item['money'] ?></p>
                                    </td>
                                    <td class="am-text-middle"><?= $item['create_time'] ?></td>
                                    <td class="am-text-middle"><?= $item['is_parent'] ?></td>
                                    <td class="am-text-middle"><?= $item['pid'] ?></td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <?php if (checkPrivilege('server.user/edit')): ?>
                                                <a class="tpl-table-black-operation-default"
                                                   href="<?= url('server.user/edit', ['dealer_id' => $item['user_id']]) ?>">
                                                    <i class="am-icon-pencil"></i> 编辑
                                                </a>
                                            <?php endif; ?>
                                            <?php if (checkPrivilege('server.user/send')): ?>
                                                <a class="j-audit" data-id="<?= $item['user_id'] ?>" data-money="<?= $item['money'] ?>"
                                                   href="javascript:void(0);">
                                                    <i class="am-icon-pencil"></i> 发放工资
                                                </a>
                                            <?php endif; ?>
                                            <?php if (checkPrivilege([
                                                'server.order/index',
                                                'server.withdraw/index',
                                                'server.user/delete',
                                                'server.user/qrcode',
                                            ], false)): ?>
                                                <div class="operation-select am-dropdown">
                                                    <button type="button"
                                                            class="am-dropdown-toggle am-btn am-btn-sm am-btn-secondary">
                                                        <span>操作</span>
                                                        <span class="am-icon-caret-down"></span>
                                                    </button>
                                                    <ul class="am-dropdown-content" data-id="<?= $item['user_id'] ?>">
                                                        <?php if (checkPrivilege('server.order/index')): ?>
                                                            <li>
                                                                <a class="" target="_blank"
                                                                   href="<?= url('server.order/index', ['user_id' => $item['user_id']]) ?>">服务人员订单</a>
                                                            </li>
                                                        <?php endif; ?>
                                                        <?php if (checkPrivilege('server.withdraw/index')): ?>
                                                            <li>
                                                                <a class="" target="_blank"
                                                                   href="<?= url('server.capital/index', ['user_id' => $item['user_id']]) ?>">提现明细</a>
                                                            </li>
                                                        <?php endif; ?>
                                                        <?php if (checkPrivilege('server.user/toBeParent')): ?>
                                                            <li>
                                                                <a data-type="become" class=""
                                                                   href="javascript:void(0);">成为管理员</a>
                                                            </li>
                                                        <?php endif; ?>
                                                        <?php if (checkPrivilege('server.user/delete')): ?>
                                                            <li>
                                                                <a data-type="delete" class=""
                                                                   href="javascript:void(0);">删除服务人员</a>
                                                            </li>
                                                        <?php endif; ?>
                                                    </ul>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="9" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                        <div class="am-u-lg-12 am-cf">
                            <div class="am-fr"><?= $list->render() ?> </div>
                            <div class="am-fr pagination-total am-margin-right">
                                <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 提现审核 -->
<script id="tpl-dealer-withdraw" type="text/template">
    <div class="am-padding-top-sm">
        <form class="form-dealer-withdraw am-form tpl-form-line-form" method="post"
              action="<?= url('server.withdraw/submit') ?>">
            <input type="hidden" name="id" value="{{ id }}">
            <div class="am-form-group">
                <label class="am-u-sm-3 am-form-label"> 开始时间 </label>
                <div class="am-u-sm-9">
                    <!-- <input type="text" class="tpl-form-input am-form-field" name="withdraw[start_time]" placeholder="开始时间" name="withdraw[start_time]" data-am-datepicker required readonly
                           value=""> -->
                           <input class="start_time" type="date" onchange="upperCase()" >
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-sm-3 am-form-label"> 结束时间 </label>
                <div class="am-u-sm-9">
                    <!-- <input type="text" class="tpl-form-input am-form-field" name="withdraw[start_time]" placeholder="开始时间" name="withdraw[start_time]" data-am-datepicker required readonly
                           value=""> -->
                           <input type="date" class="over_time" onchange="upperCase()">
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-sm-3 am-form-label"> 可提现额度 </label>
                <div class="am-u-sm-9">
                    <input type="text" class="tpl-form-input" id="ke_Money" name="withdraw[total_money]"
                           value="{{ money }}" readonly>
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-sm-3 am-form-label"> 提现金额 </label>
                <div class="am-u-sm-9">
                    <input type="text" class="tpl-form-input" name="withdraw[money]" placeholder="输入提现金额"
                           value="">
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-sm-3 am-form-label"> 理由 </label>
                <div class="am-u-sm-9">
                    <input type="text" class="tpl-form-input" name="withdraw[remark]" placeholder="填写理由"
                           value="">
                </div>
            </div>
        </form>
    </div>
</script>

<script>
var obj = {}
  function upperCase(){
    var start_time = $('.start_time').val()
    var over_time = $('.over_time').val()
    if(start_time && over_time && obj){
      var dateTime = new Date(over_time)
      dateTime=dateTime.setDate(dateTime.getDate()+1);
      dateTime=new Date(dateTime);
      
      var year = dateTime.getFullYear();
      var month = dateTime.getMonth() + 1
      if (month < 10) month = "0" + month;
      var date = dateTime.getDate();
      if (date < 10) date = "0" + date;

      over_time = year + '-' + month + '-' + date
      console.log(over_time)

      $.post('index.php?s=/store/server.user/timemoney',{start_time:start_time,over_time:over_time,user_id:obj.id},function(res){
        console.log(res)
        $('#ke_Money').val(res.data)
        console.log($('#ke_Money').val())
      })
    }else{
      
    }
  }
    $(function () {
        /**
         * 注册操作事件
         * @type {jQuery|HTMLElement}
         */
        var $dropdown = $('.operation-select');
        $dropdown.dropdown();
        $dropdown.on('click', 'li a', function () {
            var $this = $(this)
                , id = $this.parent().parent().data('id');
            if ($this.data('type') === 'delete') {
                layer.confirm(
                    '确定要删除吗？'
                    , {title: '友情提示'}
                    , function (index) {
                        $.post("<?= url('server.user/delete') ?>", {dealer_id: id}, function (result) {
                            result.code === 1 ? $.show_success(result.msg, result.url)
                                : $.show_error(result.msg);
                        });
                        layer.close(index);
                    }
                );
            }

            if ($this.data('type') === 'become') {
                layer.confirm(
                    '确定要成为管理员吗？'
                    , {title: '友情提示'}
                    , function (index) {
                        $.post("<?= url('server.user/toBeParent') ?>", {user_id: id}, function (result) {
                            result.code === 1 ? $.show_success(result.msg, result.url)
                                : $.show_error(result.msg);
                        });
                        layer.close(index);
                    }
                );
            }

            $dropdown.dropdown('close');
        });

   /*
   * index.php?s=/store/server.user/toBeParent（user_id）    服务人员升级为管理员
   * index.php?s=/store/server.user/parentList    获取管理员列表
   * index.php?s=/store/server.user/joinTeam (user_id,parent_id)     选择加入团队
   /

        /**
         * 审核操作
         */
        $('.j-audit').click(function () {
            var $this = $(this);
            console.log($this.data());
            obj = $this.data()
            layer.open({
                type: 1
                , title: '提现审核'
                , area: '340px'
                , offset: 'auto'
                , anim: 1
                , closeBtn: 1
                , shade: 0.3
                , btn: ['确定', '取消']
                , content: template('tpl-dealer-withdraw', $this.data())
                , success: function (layero) {
                    // 注册radio组件
                    layero.find('input[type=radio]').uCheck();
                }
                , yes: function (index, layero) {
                    // 表单提交
                    layero.find('.form-dealer-withdraw').ajaxSubmit({
                        type: 'post',
                        dataType: 'json',
                        success: function (result) {
                            result.code === 1 ? $.show_success(result.msg, result.url)
                                : $.show_error(result.msg);
                        }
                    });
                    layer.close(index);
                }
            });
        });
    });
</script>
